<template>
	<view :style="$s.view_color">
		<my-navbar :name="nav_title"></my-navbar>
		
		<car-comment :list="list" :topdata="topdata"></car-comment>
		
		<u-loadmore  :status="loading_status" :line="true" :loading-text="loading_text" :loadmore-text="loadmore_text" :nomore-text="nomore_text" marginTop="20"/>
	</view>
</template>

<script>
	import { mapState,mapMutations } from 'vuex'
	export default {
		data() {
			return {
				nav_title:'评价列表',
				topdata:{},
				car_id:0,
				nodata:false,
				loading_status:'loadmore',
				loading_text: '努力加载中',
				loadmore_text: '加载更多',
				nomore_text: '实在没有了',
				list:[],
				page_no:1,
				page_count:1,
			}
		},
		onLoad(option){
			if(option.id!=undefined){
				this.car_id=option.id
			}
			this.initData()
		},
		onShow(){
			
		},
		computed:{
			...mapState({
				$s:state => state.$style,
			}),
		},
		onReachBottom(){
			if(this.loading_status === 'loadmore') {
				this.getList()
			}
		},
		methods: {
			initData(){
				this.getList()
			},
			//获取列表
			getList(){				
				this.loading_status="loading"
				let page=this.page_no
				let count=this.page_count
				let selft=this
				let limit=10
				if(page>count){			//最后一页
					this.loading_status="nomore"
				}else{
					this.$u.api.commentList({car_id:this.car_id,page:page,limit:limit}).then(res=>{
						if(page===1){
							// 如果有传汽车ID，着显示评分
							if(this.car_id>0){
								this.topdata=res.data
							}else{
								this.topdata=null
							}
							this.list=res.data.list
						}else{
							this.list=this.list.concat(res.data.list)
						}
						//改变状态
						this.loading_status=page>=res.data.count?'nomore':'loadmore'
						
						this.page_no=res.data.page+1
						this.page_count=res.data.count
					})
				}
				console.log(this.list)
			},
		}
	}
</script>

<style lang="scss">
</style>
